﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1.用户控件
{
    public partial class TiHuanString : UserControl
    {
        public TiHuanString()
        {
            InitializeComponent();
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            string yuanshi = textBox3.Text;
            string val1 = textBox4.Text;
            string val2 = textBox8.Text;

            string[] list = yuanshi.Split(Environment.NewLine.ToCharArray());
            string[] val1list = val1.Split(Environment.NewLine.ToCharArray());
            string[] val2list = val2.Split(Environment.NewLine.ToCharArray());

            if (val1list.Count() != val2list.Count()) { MessageBox.Show("要替换的和替换的集合数量不同意！");return; }

            foreach (var item in list)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    string dangitem = item;
                    for (int i = 0; i < val1list.Count(); i++)
                    {
                        if (!string.IsNullOrEmpty(val1list[i]))
                        {
                            string yaoti = val1list[i];
                            string ti = val2list[i];
                            if (dangitem.Equals(yaoti))
                            {
                                dangitem = item.Replace(yaoti, ti);
                                break;
                            }
                            
                        }

                    }
                    textBox1.Text += dangitem + "\r\n";

                }
            }
            

        }
        private void button2_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(textBox1.Text);
        }
        private void textBox3_DoubleClick(object sender, EventArgs e)
        {
            textBox3.Focus();
            textBox3.SelectAll();
        }

        private void textBox4_DoubleClick(object sender, EventArgs e)
        {
            textBox4.Focus();
            textBox4.SelectAll();
        }

        private void textBox8_DoubleClick(object sender, EventArgs e)
        {
            textBox8.Focus();
            textBox8.SelectAll();
        }

        private void textBox1_DoubleClick(object sender, EventArgs e)
        {
            textBox1.Focus();
            textBox1.SelectAll();
        }
        
    }
}
